home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / rayshade / libray / libtext / bump.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  1KB  |  59 lines

  1. /*
  2.  * bump.c
  3.  *
  4.  * Copyright (C) 1989, 1991, Craig E. Kolb
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  *
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  * $Id: bump.c,v 4.0 91/07/17 14:41:39 kolb Exp Locker: kolb $
  17.  *
  18.  * $Log:    bump.c,v $
  19.  * Revision 4.0  91/07/17  14:41:39  kolb
  20.  * Initial version.
  21.  * 
  22.  */
  23. #include "texture.h"
  24. #include "bump.h"
  25.  
  26. /*
  27.  * Create and return a reference to a "bump" texture.
  28.  */
  29. Bump *
  30. BumpCreate(size)
  31. Float size;
  32. {
  33.     Bump *bump;
  34.  
  35.     bump = (Bump *)Malloc(sizeof(Bump));
  36.     bump->size = size;
  37.     return bump;
  38. }
  39.  
  40. /*
  41.  * Apply a "bump" texture.
  42.  */
  43. void
  44. BumpApply(bump, prim, ray, pos, norm, gnorm, surf)
  45. Bump *bump;
  46. Geom *prim;
  47. Ray *ray;
  48. Vector *pos, *norm, *gnorm;
  49. Surface *surf;
  50. {
  51.     Vector disp;
  52.  
  53.     DNoise3(pos, &disp);
  54.     norm->x += disp.x * bump->size;
  55.     norm->y += disp.y * bump->size;
  56.     norm->z += disp.z * bump->size;
  57.     (void)VecNormalize(norm);
  58. }
  59.